
let uu = document.querySelector(".uu")
let info = document.querySelector(".info")
fetch("http://chst.vip:1234/api/getbaicaijiatitle")
    .then(body => body.json())
    .then(res => {
        let html = ""
        res.result.forEach(item => {
            html += `<li titleid=${item.titleId}>${item.title}</li>`
        })
        uu.innerHTML = html
       uu.onmousedown=function(e){
           let start=e.pageX
           console.log(start)
           uu.onmousemove=function(e){
              let movex=e.pageX-start
               uu.style.left=-movex+"px"
           }
       }
       uu.mouseup=function(){
           uu.mousemove=null
       }
        
        let lis = uu.children
        $.ajax({
            url: "http://chst.vip:1234/api/getbaicaijiaproduct?titleid=0"
        })
            .then(res => {
                let html2 = ""
                res.result.forEach(item => {
                    html2 += `<li> 
                <a href="" class="fix"> 
                ${item.productImg}
                </a>
                <div class="infor">
            <div class="title">
                <h4>
                ${item.productName}
                </h4>
                <div class="price">
                ${item.productPrice}
                </div>
            </div>   
            <div class="down">
                <div class="bar">
                <div class="bar_in" style="width: 0px;">0%</div>
                </div>
                <span class="yiling">已领0张/剩余126张</span>
                <div class="click">
                <div class="left">${item.productCoupon}</div>
                <div class="right">${item.productHref}</div>
                </div>
            </div>     
                </div>  
                   </li>`

                })
                info.innerHTML = html2
              
                let a = 0
                let interval = setInterval(() => {
                    a++
                    Array.from($(".bar_in")).forEach(item => {
                        item.innerHTML = a + '%'
                        item.style.width = a + "%"
                    })

                    if (a >= 100) {
                        clearInterval(interval)
                    }
                }, 20);
                let b = 126
                let c = 0
                let timer = setInterval(() => {
                    c++
                    b--
                    Array.from($(".yiling")).forEach(item => {
                        item.innerHTML = `已领${c}张/剩余${b}张`
                    })
                    if (b === 0 && c === 126) {
                        clearInterval(timer)
                    }
                }, 15);
            });
        [...lis].forEach(li => {
            li.onclick = function () {
                let titleid = this.getAttribute("titleid")
                $.ajax({
                    url: "http://chst.vip:1234/api/getbaicaijiaproduct",
                    data: {
                        titleid
                    }
                })
                    .then(res => {
                        let html1 = ""
                        res.result.forEach(item => {
                            html1 += `<li> 
                            <a href="" class="fix"> 
                            ${item.productImg}
                            </a>
                            <div class="infor">
                        <div class="title">
                            <h4>
                            ${item.productName}
                            </h4>
                            <div class="price">
                            ${item.productPrice}
                            </div>
                        </div>
                            
                        <div class="down">
                            <div class="bar">
                            <div class="bar_in" style="width: 118px;">100%</div>
                            </div>
                            <span class="yiling">已领126张/剩余0张</span>
                            <div class="click">
                            <div class="left">${item.productCoupon}</div>
                            <div class="right">${item.productHref}</div>
                            </div>
                        </div>     
                            </div>  
                               </li>`

                        })
                        info.innerHTML = html1
                        let a = 0
                let interval = setInterval(() => {
                    a++
                    Array.from($(".bar_in")).forEach(item => {
                        item.innerHTML = a + '%'
                        item.style.width = a + "%"
                    })

                    if (a >= 100) {
                        clearInterval(interval)
                    }
                }, 20);
                let b = 126
                let c = 0
                let timer = setInterval(() => {
                    c++
                    b--
                    Array.from($(".yiling")).forEach(item => {
                        item.innerHTML = `已领${c}张/剩余${b}张`
                    })
                    if (b === 0 && c === 126) {
                        clearInterval(timer)
                    }
                }, 15);
                    })
            }
        })
        let btn=document.querySelector(".rol3")
        window.onscroll=function(){ 
            btn.onclick=function(){
               document.documentElement.scrollTop=0
            }

        }
    })

